package 代码记录.Bit48天集训;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**1.微信红包
 * 2.计算字符串的编辑距离(leetcode：编辑距离)
 * @author zx
 * @create 2022-05-20 8:51
 */
public class day_23 {
    /**
     * @return 自己做出来了
     */
    public int getValue(int[] gifts, int n) {
        Map<Integer,Integer> map = new HashMap<>();
        for(int i = 0;i < gifts.length;i++){
            if(map.containsKey(gifts[i])){
                map.put(gifts[i],map.get(gifts[i]) + 1);
            }else{
                map.put(gifts[i],1);
            }
        }
        int res = 0;
        for(Map.Entry<Integer,Integer> entry : map.entrySet()){
            if(entry.getValue() > n / 2){
                res = entry.getKey();
            }
        }
        return res;
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str1 = sc.nextLine();
        String str2 = sc.nextLine();
        int n = str1.length();
        int m = str2.length();
        // 有一个字符串为空串
        if (n * m == 0) {
            System.out.println(n + m);
        }

        // DP 数组
        int[][] D = new int[n + 1][m + 1];

        // 边界状态初始化
        for (int i = 0; i < n + 1; i++) {
            D[i][0] = i;
        }
        for (int j = 0; j < m + 1; j++) {
            D[0][j] = j;
        }

        // 计算所有 DP 值
        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < m + 1; j++) {
                int left = D[i - 1][j] + 1;
                int down = D[i][j - 1] + 1;
                int left_down = D[i - 1][j - 1];
                if (str1.charAt(i - 1) != str2.charAt(j - 1)) {
                    left_down += 1;
                }
                D[i][j] = Math.min(left, Math.min(down, left_down));
            }
        }
        System.out.println(D[n][m]);
    }
}
